<%@ page import="java.util.HashMap" %>
<%@ page import="static com.weavernorth.util.dateUtils.getNowDateTime" %>
<%@ page import="com.weavernorth.fadada.pojo.AccountRegistPoJo" %>
<%@ page import="com.weavernorth.util.MyCrypUtils" %>
<%@ page import="com.weavernorth.fadada.util.fadadaUtil" %>
<%@ page import="com.weaver.general.Util" %>
<%@ page import="static com.weavernorth.fadada.util.fadadaUtil.connectUrlWithTimeOut" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.alibaba.fastjson.serializer.SerializerFeature" %>
<%@ page import="java.util.Map" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%
    Map<String,Object> msg=new HashMap<>();
    String strSign = "";
    String timestamp = "";
    String biz_content = "";
    //region [公共参数]
    timestamp = getNowDateTime();
    //配置接口路径
    HashMap<String, String> urlMap = new HashMap<>();
    urlMap.put("账户注册", "/account/register");
    urlMap.put("创建合同模板", "/contract/template/save");
    urlMap.put("查询模板", "/online-template/company/list");
    urlMap.put("模板填充", "/contract/generate");
    urlMap.put("查询客户编号", "/company/customer-id/list");
    //endregion
    String query_str="";
    String str_query_list="";
    String isQuery = Util.null2String(request.getParameter("isQuery"));
    String cType="查询客户编号";
    if(isQuery.equals("query")){
        String q_CompanyName = Util.null2String(request.getParameter("q_companyName"));//企业名称
        Boolean isConnect=connectUrlWithTimeOut(fadadaUtil.api_url_prefix+urlMap.get("查询客户编号"),2000);
        if (isConnect) {
            biz_content = fadadaUtil.queryCustomer(q_CompanyName);
            query_str = "appId=" + fadadaUtil.appId + "&bizContent=" + biz_content + "&signType=" + fadadaUtil.signType + "&timestamp=" + timestamp;//待签名字符串
            try {
                strSign = MyCrypUtils.sh256Encrypt(query_str).toUpperCase();
                strSign = MyCrypUtils.sh256Encrypt(strSign + fadadaUtil.appkey).toUpperCase();
                strSign = MyCrypUtils.Base64Encode((strSign).getBytes());
            } catch (Exception ex) {
                System.out.println("sha256异常,异常信息：" + ex.toString());
            }
            HashMap<String, Object> params = fadadaUtil.getParams(timestamp, strSign, biz_content);
            str_query_list = fadadaUtil.sedDataTofdd(urlMap.get("查询客户编号"), params);
        }else{
            str_query_list="连接不可用";
        }
        try{
            Object parse = JSONObject.parse(str_query_list);
        }catch (Exception ex){
            str_query_list="返回结果不是一个标准的json字符串,请联系管理员！";
        }

        msg.put("返回结果：",str_query_list);
    }
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>查询客户编号</title>
    <script src="/js/jquery/jquery_wev8.js"></script>
    <script type="text/javascript">
        function query() {
            frm.isQuery.value="query";
            frm.submit();
        }
    </script>
</head>
<body>
<h1>查询客户编号</h1>
<form name="frm" method="post" action="queryCustomer.jsp" >
    <input type="hidden" name="isQuery" value="">
    <div style="margin: auto">
        <table>
            <tr>
                <td>企业名称：</td>
                <td><input type="text" name="q_companyName" id="q_companyName"/></td>
            </tr>
        </table>
    </div>
    <input type="submit"  value="查询" onclick="query()"/>
    <div id="json" style="padding-left: 10px">
        执行结果：<%=JSONObject.toJSONString(msg, SerializerFeature.DisableCircularReferenceDetect) %>
    </div>
</form>
</body>
</html>